<%@ page contentType="text/html;charset=UTF-8" isErrorPage="true"%>
<%@ include file="/comm/include.jsp"%>
<script type="text/javascript">
$(function(){
	$('#data').datagrid({  
	    url:'${ctx}/announcement/list.htm',
	    pagination:true,
	    checkOnSelect:false,
	    singleSelect:true,
	    idField:'id',
	    nowrap:true,
	    rownumbers:true,
	    columns:[[
	        {field:'id',hidden:true,width:150},
	        {field:'title',title:'公告标题',width:150},
	        {field:'content',title:'公告内容',width:350},
	        {field:'createTime',title:'发布时间'}
	    ]],
	    toolbar:"#tb",
	    onDblClickRow:function(rowIndex, rowData){
	    	$('#content').html(rowData.content);
            $('#showDetail').dialog('open').dialog('setTitle','公告内容');
		}
	});
	
	$("#addObj").click(function(){
        url = "${ctx}/announcement/add.htm";
		$('#optAnnouncement').dialog('open').dialog('setTitle','添加公告');
        $('#rebateForm').form('clear');
	});
	$("#editObj").click(function(){
		var row = $('#data').datagrid('getSelected');
        if (row){
			url = "${ctx}/announcement/update.htm";
	        $('#optAnnouncement').dialog('open').dialog('setTitle','编辑公告');
	        $('#rebateForm').form('load',row);
        }
	});
});
var url='';
function submitForm(){
	$('#rebateForm').form('submit',{  
		url: url,
	    onSubmit: function(){
			return $(this).form('validate');
	    },  
	    success:function(data){
	    	if (data == 1) {
	    		$('#optAnnouncement').dialog('close'); //成功后关闭对话框
	    		$('#data').datagrid('reload');//重新加载
			}else {
		    	alert('公告操作失败');
			}
	    }
	}); 
}

</script>
<div>
	<table id="data"></table>
	<div id="tb" style="padding:5px;height:auto">
		<div>
			<a href="javascript:;" id="addObj" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加公告</a> 
			<a href="javascript:;" id="editObj" class="easyui-linkbutton" iconCls="icon-edit-sn" plain="true">编辑公告</a> 
		</div>
	</div>
	<div id="showDetail" class="easyui-dialog" data-options="closed:true,maximizable:true" style="width:400px;height:280px;padding:5px">
            <div id="content"></div>
     </div>
	<div id="optAnnouncement" class="easyui-dialog" data-options="closed:true,maximizable:false" style="width:400px;height:280px;padding:5px">
            <form id="rebateForm" method="post">
				<div>
					<div class="form-field" style="padding: 1px;" >
						<p>
							<label class="name" for="title" >公告标题:</label>
							<input type="hidden" id="id" name="id" value=""/>
							<input type="text" id="title" name="title" class="easyui-validatebox"  data-options="required:true" value=""/>
						</p>
						<p>
							<label class="name" for="content" >公告内容:</label>
							<textarea id="content" cols="30" rows="5" name="content" class="easyui-validatebox"  data-options="required:true"></textarea>
						</p>
						<p align="center" class="form-actions">
							<a  onclick="submitForm();" href="javascript:;" class="easyui-linkbutton" iconCls="icon-save">保存</a>
						</p>
					</div>
				</div>
			</form>	
     </div>
</div>

